package gazzera.swing;

import gazzera.swing.components.Box;
import gazzera.swing.utility.*;

import java.awt.*;
import java.util.*;

import javax.swing.*;



public class ConfigWindow extends JFrame
{
	JLabel banner;
	JTextField nickname;
	JTextField port;

	public ConfigWindow() throws HeadlessException
	{
		super("Welcome to Gazzera");
		Box b = new Box(true);
		banner = new JLabel(new ImageIcon(ResourceLoader.get("gazzera.png")));
		setSize(430, 400);
		b.add(banner, false);
		setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		
		
		

		JPanel p = createOptionPanel();


		//Lay out the panel.
		SpringUtilities.makeCompactGrid(p,
		                                2, 2, //rows, cols
		                                6, 6,        //initX, initY
		                                6, 6);       //xPad, yPad

		b.add(new JLabel("<html><b>Enter your configuration</b></html>", JLabel.CENTER), false);
		b.add(p, false);
		b.add(new JPanel(), true);
		
		Box buttons = new Box(false);
		buttons.add(new JButton("Ok"));
		buttons.add(new JButton("Cancel"));
		b.add(buttons, false);
		
		add(b);
	}

	private JPanel createOptionPanel()
	{
		//Create and populate the panel.
		JPanel p = new JPanel(new SpringLayout());
		
		    JLabel l = new JLabel("Nickname", JLabel.TRAILING);
		    p.add(l);
		    nickname = new JTextField(10);
		    nickname.setText(System.getProperty("user.name"));
		    l.setLabelFor(nickname);
		    p.add(nickname);

		    l = new JLabel("Port", JLabel.TRAILING);
		    p.add(l);
		    port = new JTextField(10);
		    port.setText(""+(new Random(System.currentTimeMillis()).nextInt(5000)+5000));
		    l.setLabelFor(port);
		    p.add(port);
		return p;
	}
	
	
	
	
}
